<?php
/**
 * @file
 * Contains the theme's functions to manipulate Drupal's default markup.
 *
 * Complete documentation for this file is available online.
 * @see https://drupal.org/node/1728096
 */


/**
 * Override or insert variables into the maintenance page template.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("maintenance_page" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_maintenance_page(&$variables, $hook) {
  // When a variable is manipulated or added in preprocess_html or
  // preprocess_page, that same work is probably needed for the maintenance page
  // as well, so we can just re-use those functions to do that work here.
  hktv2_preprocess_html($variables, $hook);
  hktv2_preprocess_page($variables, $hook);
}
// */

/**
 * Override or insert variables into the html templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("html" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_html(&$variables, $hook) {
  $variables['sample_variable'] = t('Lorem ipsum.');

  // The body tag's classes are controlled by the $classes_array variable. To
  // remove a class from $classes_array, use array_diff().
  //$variables['classes_array'] = array_diff($variables['classes_array'], array('class-to-remove'));
}
// */

/**
 * Override or insert variables into the page templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("page" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_page(&$variables, $hook) {
  $variables['sample_variable'] = t('Lorem ipsum.');
}
// */

/**
 * Override or insert variables into the node templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("node" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_node(&$variables, $hook) {
  $variables['sample_variable'] = t('Lorem ipsum.');

  // Optionally, run node-type-specific preprocess functions, like
  // hktv2_preprocess_node_page() or hktv2_preprocess_node_story().
  $function = __FUNCTION__ . '_' . $variables['node']->type;
  if (function_exists($function)) {
    $function($variables, $hook);
  }
}
// */

/**
 * Override or insert variables into the comment templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("comment" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_comment(&$variables, $hook) {
  $variables['sample_variable'] = t('Lorem ipsum.');
}
// */

/**
 * Override or insert variables into the region templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("region" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_region(&$variables, $hook) {
  // Don't use Zen's region--sidebar.tpl.php template for sidebars.
  //if (strpos($variables['region'], 'sidebar_') === 0) {
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('region__sidebar'));
  //}
}
// */

/**
 * Override or insert variables into the block templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("block" in this case.)
 */
/* -- Delete this line if you want to use this function
function hktv2_preprocess_block(&$variables, $hook) {
  // Add a count to all the blocks in the region.
  // $variables['classes_array'][] = 'count-' . $variables['block_id'];

  // By default, Zen will use the block--no-wrapper.tpl.php for the main
  // content. This optional bit of code undoes that:
  //if ($variables['block_html_id'] == 'block-system-main') {
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
  //}
}
// */


/*
function hktv2_theme($existing, $type, $theme, $path) {
  return array(
    'comment_form' => array(
      'render element' => 'form',
    ), 
  );
}  */

/*function hktv2_comment_form(&$variables) {
//php magic here
if($logged_in) {
  $user = user_load($user->uid);
  print theme('image_style', array('style_name' => 'thumbnail', 'path' => $user->picture->uri));
}
}


function hktv2_comment_form(&$variables) {
  hide($variables['form']['comment_body']['und']['0']['format']);
  $comment_form = drupal_render_children($variables['form']);
  
  return $comment_form;

}
 */

/*
function hktv2_comment_form(&$variables) {
//php magic here
if($logged_in) {
  $user = user_load($user->uid);
  print theme('image_style', array('style_name' => 'thumbnail', 'path' => $user->picture->uri));
}
}

function hktv2_comment_form(&$variables) {
  hide($variables['form']['comment_body']['und']['0']['format']);
  $comment_form = drupal_render_children($variables['form']);
  
  return $comment_form;

}*/



/**
* Override or insert variables into all templates.
*
* @param $vars
*   An array of variables to pass to the theme template.
* @param $hook
*   The name of the template being rendered (name of the .tpl.php file.)
*/
//function hktv2_preprocess(&$vars, $hook) {
//  
//  
//  //print_r($vars);
//  //$vars['sample_variable'] = t('Lorem ipsum.');
//  $css = $vars['css'];
//  
//  
//  print_r($css);
//  unset($css['all']['module']);
//  $vars['styles'] = drupal_get_css($css);
//}
//
//
//
//
//删除默认的css文件
function hktv2_css_alter(&$css) {
 
// Remove Drupal core css
 
$exclude = array(
'modules/aggregator/aggregator.css' => FALSE,
'modules/block/block.css' => FALSE,
'modules/book/book.css' => FALSE,
'modules/comment/comment.css' => FALSE,
'modules/dblog/dblog.css' => FALSE,
'modules/field/theme/field.css' => FALSE,
'modules/file/file.css' => FALSE,
'modules/filter/filter.css' => FALSE,
'modules/forum/forum.css' => FALSE,
'modules/help/help.css' => FALSE,
'modules/menu/menu.css' => FALSE,
'modules/node/node.css' => FALSE,
'modules/openid/openid.css' => FALSE,
'modules/poll/poll.css' => FALSE,
'modules/profile/profile.css' => FALSE,
'modules/search/search.css' => FALSE,
'modules/statistics/statistics.css' => FALSE,
'modules/syslog/syslog.css' => FALSE,
'modules/system/admin.css' => FALSE,
'modules/system/maintenance.css' => FALSE,
'modules/system/system.css' => FALSE,
'modules/system/system.admin.css' => FALSE,
'modules/system/system.base.css' => FALSE,
'modules/system/system.maintenance.css' => FALSE,
'modules/system/system.messages.css' => FALSE,
'modules/system/system.menus.css' => FALSE,
'modules/system/system.theme.css' => FALSE,
'modules/taxonomy/taxonomy.css' => FALSE,
'modules/tracker/tracker.css' => FALSE,
'modules/update/update.css' => FALSE,
'modules/user/user.css' => FALSE,
'misc/vertical-tabs.css' => FALSE,


'modules/toolbar/toolbar.css' => FALSE,
'modules/user/user.css' => FALSE,
'modules/user/user.css' => FALSE,
'modules/user/user.css' => FALSE,
 
// Remove contrib module CSS
drupal_get_path('module', 'views') . '/css/views.css' => FALSE, );
$css = array_diff_key($css, $exclude);
 
}

//删除系统js文件
function hktv2_js_alter(&$js) {
    unset(
        $js['misc/drupal.js'],
        $js['misc/jquery.js']
     
    );
}



//定制单独页面添加js和css文件


function hktv2_preprocess_html(&$vars) {
 
 
/**
 * Reset all css files.
 */
// drupal_static_reset('drupal_add_css');
 
/**
 * Add theme css files.
 */
 drupal_add_css(path_to_theme() .'/css/main.css.less', array('group' => CSS_THEME, 'every_page' => TRUE, 'weight' => -20));
 
//  drupal_add_css(path_to_theme() .'/assets/css/cascade/production/build-full.min.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'weight' => -19));
 
 /**
 * Add innerpage.css theme css file if current page is not frontpage.
 */
 
 if (!drupal_is_front_page()) {
 drupal_add_css(path_to_theme() .'/css/innerpage.css', array('group' => CSS_THEME, 'every_page' => TRUE, 'weight' => -20));  
    }
 
 
 
 /**
 * Check if the current page is front page and remove innerpage.css file.
 */
 
if (drupal_is_front_page()) {
    if (isset($css[drupal_get_path('theme','hktv2') .'/css/innerpage.css'])) {
        unset($css[drupal_get_path('theme','hktv2') .'/css/innerpage.css']);
    }
    drupal_add_css(path_to_theme() .'/css/homepage.css', array('group' => CSS_THEME, 'every_page' => FALSE));
    }
 
 
/**
 * If user is logged in add system css files.
 */
 
 if(user_is_logged_in() == 1) {
 //   drupal_add_css(drupal_get_path('module', 'toolbar') . '/toolbar.css', array('group' => CSS_THEME));
 //   drupal_add_css(drupal_get_path('module', 'system') . '/system.base.css', array('group' => CSS_SYSTEM, 'preprocess' => TRUE)); 
    }
 
 
/**
 * Reset all js files.
 */
 
// drupal_static_reset('drupal_add_js');
 
/**
 * Add theme js files.
 */
  drupal_add_js(path_to_theme() . '/js/main.js', 'file'); 
 
  /**
 * If user is logged in add system js files.
 */
   if(user_is_logged_in() == 1) {
   drupal_add_js($GLOBALS['base_url'] .'/misc/drupal.js','file');
   drupal_add_js(drupal_get_path('module', 'overlay') .'/overlay-parent.js', 'file');
   drupal_add_js(drupal_get_path('module', 'toolbar') .'/toolbar.js', 'file');
   }
 
 
 
/**
 * Add theme if not frontpage js file.
 */
 
  if (!drupal_is_front_page()) {
  drupal_add_js(path_to_theme() . '/js/innerpage.js', 'file');
  }
 
 
 
/**
 * Add theme frontpage js file.
 */
 
  if (drupal_is_front_page()) {
  drupal_add_js(path_to_theme() . '/js/homepage.js', 'file');
  }
  /**
 * 内容类型
 */
 print_r($vars['theme_hook_suggestions']);
  
  if ($node = menu_get_object()) {
	  
	  print_r($node);
		if($node->type) {
			$vars['theme_hook_suggestions'][] = 'html__' . $node->type;
		}
	}
  
   
  
  
 }


//定制自由的模版候选方案

/**
 * Implements hook_entity_info_alter().
 */
function hktv2_entity_info_alter(&$entity_info) {

	// Add a new 'page' view mode to be used exclusively for nodes displayed when viewing a page.
	$entity_info['node']['view modes']['page'] = array(
		'label' => t('Page'),
		'custom settings' => TRUE,
	);

	// Add a new 'panel' view mode to be used exclusively for nodes displayed inside a panel.
	$entity_info['node']['view modes']['panel'] = array(
		'label' => t('Panel'),
		'custom settings' => TRUE,
	);

	// Add a new 'block' view mode to be used exclusively for nodes displayed by a block.
	$entity_info['node']['view modes']['block'] = array(
		'label' => t('Block'),
		'custom settings' => TRUE,
	);

	// Add a new 'block' view mode to be used exclusively for nodes displayed on a term page.
	$entity_info['node']['view modes']['term'] = array(
		'label' => t('Attached To Term'),
		'custom settings' => TRUE,
	);

	// Add a new 'teaser' view mode to be used for taxonomy terms.
	$entity_info['taxonomy_term']['view modes']['teaser'] = array(
		'label' => t('Teaser'),
		'custom settings' => TRUE,
	);

	// Add a new 'teaser' view mode to be used for users.
	$entity_info['user']['view modes']['teaser'] = array(
		'label' => t('Teaser'),
		'custom settings' => TRUE,
	);
                                                     
	if (isset($entity_info['field_collection_item'])) {
		$entity_info['field_collection_item']['view modes']['teaser'] = array(
			'label' => t('Teaser'),
			'custom settings' => TRUE,
		);
	}


}

/**
 * Implements hook_preprocess_taxonomy_term().
 * @param array $variables
 */
function hktv2_preprocess_taxonomy_term(&$variables) {
	$variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $variables['vocabulary_machine_name'];
	$variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $variables['vocabulary_machine_name'] . '__' . $variables['view_mode'];
}

/**
 * Implements hook_preprocess_node().
 *
 * @param array $variables
 */
function hktv2_preprocess_node(&$variables) {
	$variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__' . $variables['view_mode'];
}





//定制表单
 
 
 function hktv2_form_alter(&$form, &$form_state, $form_id) {
//if ($form_id == 'search_block_form') {
//$form['actions']['submit']['#type'] = 'button';
//$form['actions']['submit']['#attributes']['class'][] = 'icon-search';
//}
   
   
   if ($form_id == 'search_block_form') {
    $form['actions']['button']['#prefix'] = '<button type="submit">';
    $form['actions']['button']['#suffix'] = '</button>';
    $form['actions']['button']['#markup'] = '<i class="icon-search"></i>';
  }

}






//function hktv2_form_element_label($variables) {
//  
//    $element = $variables['element'];
//   // print_r($element);
//  
//}
//定制按钮
//https://api.drupal.org/api/drupal/includes%21form.inc/function/theme_button/7

//
//function hktv2_button($variables){
//  
// // print_r($variables);
// //  $element = $variables['element'];
//   
// print_r($element);
//   switch ($element["#type"])
//{
//case 'submit':
//  echo "Number 1";
//  break;
//case 2:
//  echo "Number 2";
//  break;
//case 3:
//  echo "Number 3";
//  break;
//default:
//  echo "No number between 1 and 3";
//}
//   
//
//
//
//  
//} 